#include "widget.h"
#include "ui_widget.h"
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->listWidget->addItem("C++");
    ui->listWidget->addItem("Java");
    ui->listWidget->addItem("rust");

//    ui->listWidget->addItem(new QListWidgetItem("go"));
//    ui->listWidget->addItem(new QListWidgetItem("python"));
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_insert_clicked()
{
    const QString& text = ui->lineEdit->text();
    if (text.isEmpty())
        return;
    ui->listWidget->addItem(text);
    ui->lineEdit->clear();
}

void Widget::on_pushButton_remove_clicked()
{
    int row = ui->listWidget->currentRow();
    if (row < 0)
        return;
    ui->listWidget->takeItem(row);
}

void Widget::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
    if (current)
        qDebug() << current->text();
    if (previous)
        qDebug() << previous->text();
}
